package com.ruoyi.system.service.sso;

import com.ruoyi.system.common.Md5Utils;
import com.ruoyi.system.domain.IndsvrSsoApp;
import com.ruoyi.system.domain.IndsvrSsoAppUserMap;
import jakarta.servlet.http.HttpServletRequest;
import lombok.Data;
import okhttp3.Cookie;
import org.springframework.stereotype.Component;

import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.HashMap;

@Component
public class Ladis implements SimulationLogin{
    @Override
    public Object run(IndsvrSsoApp app, IndsvrSsoAppUserMap user, HttpServletRequest request) throws Exception {


        OkHttpUtils okHttpUtils = new OkHttpUtils();
        HashMap<String, String> stringStringHashMap = new HashMap<>();
        stringStringHashMap.put("password",user.getPassword());
        stringStringHashMap.put("loginType", "local");
        String url = app.getBaseUrl()+"/ViewPower/login/userLogin";
        String s = okHttpUtils.postForForm(url,stringStringHashMap);

        HashMap<String, Cookie> cookie = okHttpUtils.getCookie(new URI(url).getHost());

        String authToken = cookie.get("JSESSIONID").value();


        Auths auths = new Auths();
        auths.token= authToken;
        return auths;
    }


    @Data
    public static class Auths{
        String token;
    }

    @Data
    public static class Token{
        private Object data;
        private String expire = null;

    }
}
